package com.grademaster.controller;

import com.grademaster.common.R;
import com.grademaster.dto.ScoreDto;
import com.grademaster.dto.ScoreManagePageDto;
import com.grademaster.dto.ScorePageDto;
import com.grademaster.service.ScoresService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;

@Slf4j
@RestController
@RequestMapping("/scores")
@Api(tags = "成绩相关接口")
@CrossOrigin(origins = {"http://localhost:8081"}, allowCredentials = "true")
public class ScoresController {

    @Autowired
    private ScoresService scoresService;

    @ApiOperation("分页查询成绩")
    @GetMapping("/list")
    public R scoresList(ScorePageDto scorePageDto){
        return scoresService.getScoresList(scorePageDto);
    }
    @ApiOperation("导出成绩列表到Excel")
    @GetMapping("/exportExcel2")
    public ResponseEntity exportExcel2(ScorePageDto scorePageDto){
        return scoresService.exportExcel2(scorePageDto);
    }

    @ApiOperation("分页查询教师管理成绩")
    @GetMapping("/listTeacher")
    public R scoresListTeacher(ScoreManagePageDto scoreManagePageDto){
        return scoresService.getScoresListTeacher(scoreManagePageDto);
    }
    @ApiOperation("成绩送审")
    @PostMapping("/submitScore/{scoreId}")
    public R submitScore(@PathVariable("scoreId") String scoreId){
        return scoresService.submitScore(scoreId);
    }
    @ApiOperation("成绩修改")
    @PostMapping("/updateScore")
    public R updateScore(@RequestBody ScoreDto scoreDto){
        return scoresService.updateScore(scoreDto);
    }
    @ApiOperation("成绩审核通过")
    @PostMapping("/passScore/{scoreId}")
    public R passScore(@PathVariable("scoreId") String scoreId){
        return scoresService.passScore(scoreId);
    }
    @ApiOperation("成绩未通过")
    @PostMapping("/noPassScore/{scoreId}")
    public R noPassScore(@PathVariable("scoreId") String scoreId){
        return scoresService.noPassScore(scoreId);
    }

    @ApiOperation("导出成绩列表到Excel")
    @GetMapping("/exportExcel")
    public ResponseEntity exportExcel(ScoreManagePageDto scoreManagePageDto) {
        return scoresService.exportExcel(scoreManagePageDto);
    }

    @ApiOperation("删除成绩")
    @DeleteMapping("/deleteScore/{scoreId}")
    public R deleteScore(@PathVariable("scoreId") String scoreId) {
        return scoresService.deleteScore(scoreId);
    }

}
